<script lang="ts" setup name="XtxCheckbox">
//
const {modelValue=false}= defineProps<{
    modelValue?:boolean
}>()

// v-model语法糖 v-model与 update:modelValue搭配
const emit =defineEmits<{
    (e:'update:modelValue',value:boolean):void
    (e:'change',value:boolean):void
}>()
// 点击切换复选框 需要通知父组件修改
const change=()=>{
   emit('update:modelValue',!modelValue)
   emit('change',!modelValue)
}
</script>

<template>
  <div class="xtx-checkbox" @click="change">
    <i v-if="modelValue" class="iconfont icon-checked"></i>
    <i v-else class="iconfont icon-unchecked"></i>
    <span>
        <slot></slot>
    </span>
  </div>
</template>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
